/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package io.renren.modules.sys.redis;


import io.renren.common.utils.RedisKeys;
import io.renren.common.utils.RedisUtils;
import io.renren.modules.sys.entity.SysConfigEntity;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * 系统配置Redis
 *
 * @author Mark sunlightcs@gmail.com
 */
@Component
public class SysConfigRedis {
  @Resource
  private RedisUtils redisUtils;

  public void saveOrUpdate(SysConfigEntity config) {
    if (config == null) {
      return;
    }
    String key = RedisKeys.getSysConfigKey(config.getParamKey());
    redisUtils.set(key, config);
  }

  public void delete(String configKey) {
    String key = RedisKeys.getSysConfigKey(configKey);
    redisUtils.delete(key);
  }

  public SysConfigEntity get(String configKey) {
    String key = RedisKeys.getSysConfigKey(configKey);
    return redisUtils.get(key, SysConfigEntity.class);
  }
}
